/**
 * @Author:卿雨欣
 * @Date:20200617
 * @Describle:这是创建组合页
 */
import React, { Component } from "react";
import FundTable from "./Component_CreatPortfolio/fundTable";
import StockTable from "./Component_CreatPortfolio/stockTable";
import CreatButton from "./Component_CreatPortfolio/creatButton";
import {Card} from "antd";

//声明全局变量、常量

export default class CreatPortfolio extends Component{
    constructor() {
        super();
        this.state={
            selectedStocks:[],
            selectedFunds:[],
            shareLength:0,
            fdShareLength:0
        }
    }
    //获取子组件传回的股票列表
    handleStocks(stock) {
        this.state.selectedStocks = [];
        this.state.selectedStocks.push(stock);
        this.setState({
            selectedStocks: this.state.selectedStocks,
        });
    }
    //获取子组件传回的基金列表
    handleFunds(fund,fdShareLength) {
        this.state.selectedFunds = [];
        this.state.selectedFunds.push(fund);
        this.setState({
            selectedFunds: this.state.selectedFunds,
        });
    }
    // 处理子组件传回的策略规定的股票产品数量
    handleShareLength(shareLength){
        this.setState({
            shareLength:shareLength,
        });
    }
    //处理子组件传回的策略规定的基金产品数量
    handleFdShareLength(fdShareLength){
        this.setState({
            fdShareLength:fdShareLength,
        });
    }
    render() {
        return (
            <div>
                <div style={{marginLeft:200,float:"left"}}>
                    <Card title="基金数量提示" style={{ width: 250 }}>
                        <p>该策略基金数量为:<span style={{color:"red",fontSize:14}}> {this.state.fdShareLength}</span> </p>
                    </Card>
                </div>
                <div style={{marginRight:200,float:"right"}}>
                    <Card title="股票数量提示" style={{ width: 200 }}>
                        <p>该策略股票数量为:<span style={{color:"red",fontSize:14}}> {this.state.shareLength} </span></p>
                    </Card>
                </div>
                <CreatButton sharelength={this.state.shareLength} //父组件传递给子组件
                             fdShareLength={this.state.fdShareLength} //父组件传递给子组件
                             strategyIdButton={this.props.strategyId} //从父组件MenuLayout组件获取策略
                             onCreat1={this.state.selectedStocks} //父组件传递给子组件
                             onCreat2={this.state.selectedFunds} //父组件传递给子组件
                />
                <FundTable onFundsLength={this.handleFdShareLength.bind(this)} //子组件传递给父组件
                           strategyIdFund={this.props.strategyId} //从父组件MenuLayout组件获取策略
                           onFunds={this.handleFunds.bind(this)} //子组件传递给父组件
                />
                <StockTable onStocksLength={this.handleShareLength.bind(this)}  //子组件传递给父组件
                            strategyIdStock={this.props.strategyId} //从父组件MenuLayout组件获取策略
                            onStocks={this.handleStocks.bind(this)} //子组件传递给父组件
                />
            </div>
        )
    }
}
